﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pika.Collections
{
    /// <summary>
    /// Représente la taille
    /// </summary>
    [Serializable]
    [System.Runtime.InteropServices.ComVisible(true)]
    public class Size
    {
        #region Champs
        protected int _columns;
        protected int _rows;
        #endregion

        #region Méthodes
        public Size(int columns, int rows)
        {
            if(columns < 0 || rows < 0)
            {
                throw new ArgumentException();
            }
            this.Columns = columns;
            this.Rows = rows;
        }
        /// <summary>
        /// Surcharge la méthode Equals
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            bool bresult;
            Size scomp;

            bresult = false;
            if((obj is Size) == true)
            {
                scomp = (Size)obj;
                bresult = ((scomp.Columns == this.Columns) &&
                    (scomp.Rows == this.Rows));
               
            }
            return bresult;
        }
        /// <summary>
        /// Surcharge la méthode GetHashCode
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.Rows ^ this.Columns;
        }
        /// <summary>
        /// Surcharge la méthode ToString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format(
                "{Columns = {0}, Rows = {1}",
                _columns,
                _rows);
        }
        #endregion

        #region Propriétés
        /// <summary>
        /// Retourne le nombre de colonnes
        /// </summary>
        public int Columns
        {
            get { return _columns; }
            protected set { _columns = value; }
        }
        /// <summary>
        /// Retourne le nombre de lignes
        /// </summary>
        public int Rows
        {
            get { return _rows; }
            protected set { _rows = value; }
        }
        #endregion
    }
}
